<template>
  <div class="mod-demo__equipmenttype" style="overflow-y: scroll;height: 800px;">
    <el-form :inline="true" :model="state.dataForm" @keyup.enter="state.getDataList()">
      <el-form-item label="设备名称">
        <el-input v-model="state.dataForm.name" placeholder="请输入设备名称" ></el-input>
      </el-form-item>
      <el-form-item label="设备状态">
        <el-select v-model="state.dataForm.state"  placeholder="请选择设备状态" >
          <el-option label="全部" value=""></el-option>
          <el-option label="启用" value="1"></el-option>
          <el-option label="禁用" value="2"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button @click="state.getDataList()">查询</el-button>
      </el-form-item>
      <el-form-item>
        <el-button  type="primary" @click="addOrUpdateHandle()">新增</el-button>
      </el-form-item>

    </el-form>
    <template>
      <el-table :data="tableData" style="width: 100%">
        <el-table-column prop="date" label="日期" width="180"></el-table-column>
        <el-table-column prop="name" label="姓名" width="180"></el-table-column>

      </el-table>
    </template>
    <el-table v-loading="state.dataListLoading" :data="state.dataList" border @selection-change="state.dataListSelectionChangeHandle" style="width: 100%">
              <el-table-column prop="name" label="设备名称" header-align="center" align="center"></el-table-column>
              <el-table-column label="设备图标">
                <template v-slot="scope">
                  <el-image
                    style="width: 100px; height: 100px"
                    :src="scope.row.url"
                    fit="fill"  @click="maxImg(scope.row.url)"></el-image>
                </template>
              </el-table-column>
              <el-table-column prop="state" label="设备状态"  header-align="center" align="center">
                <template v-slot="scope">
                  <el-tag v-if="scope.row.state === 1" size="small" type="success">启用</el-tag>
                  <el-tag v-if="scope.row.state === 2" size="small" type="danger">禁用</el-tag>
                </template>
              </el-table-column>
              <el-table-column prop="createDate" label="创建时间" header-align="center" align="center"></el-table-column>
            <el-table-column label="操作" fixed="right" header-align="center" align="center" width="150">
        <template v-slot="scope">
<!--          v-if="state.hasPermission('demo:equipmenttype:update')"
          v-if="state.hasPermission('demo:equipmenttype:delete')"-->
          <el-button  type="primary" link @click="addOrUpdateHandle(scope.row.id)">修改</el-button>
          <el-button  type="primary" link @click="state.deleteHandle(scope.row.id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination :current-page="state.page" :page-sizes="[10, 20, 50, 100]" :page-size="state.limit" :total="state.total" layout="total, sizes, prev, pager, next, jumper" @size-change="state.pageSizeChangeHandle" @current-change="state.pageCurrentChangeHandle"> </el-pagination>
    <!-- 弹窗, 新增 / 修改 -->
    <add-or-update ref="addOrUpdateRef" @refreshDataList="state.getDataList">确定</add-or-update>
    <!-- 放大图片的对话框 -->
    <el-dialog  v-model="view.dialogVisible" >
      <img width="100%" :src="view.currentImage" alt="">
    </el-dialog>
  </div>
</template>

<script lang="ts" setup>
import useView from "@/hooks/useView";
import { reactive, ref, toRefs } from "vue";
import AddOrUpdate from "./equipmenttype-add-or-update.vue";

const view = reactive({
  deleteIsBatch: true,
  getDataListURL: "/sysapp/equipmenttype/page",
  getDataListIsPage: true,
  exportURL: "/sysapp/equipmenttype/export",
  deleteURL: "/sysapp/equipmenttype",
  dialogVisible:false,
  currentImage:"",
});
const maxImg = (url?:string) => {
  debugger
  view.dialogVisible=true;
  view.currentImage =url
}
const state = reactive({ ...useView(view), ...toRefs(view) });

const addOrUpdateRef = ref();
const addOrUpdateHandle = (id?: number) => {
  addOrUpdateRef.value.init(id);
};
</script>
